#include <cstdio>

int grid[35][85];
int visited[35][85];
int N, cases;
const int space = ' ';
const int star = '*';
const int under_line = '_';
const int new_line = '\n';
const int sharp = '#';
const int cross = 'X';
const int NOT_VISITED = 0;
const int VISITED = 1;
const int ROW = 35;
const int COL = 85;

void get_newline() {
    while(getchar() != new_line) {
    }
}

void input() {
    bool bLoop = true;
    char c = star;
    int row = 0, col = 0;
    while(bLoop || c != new_line) {
        c = getchar();
        if(c == under_line) {
            bLoop = false;
        }
        if(c != new_line) {
            grid[row][col] = c;
        }
        ++col;
        if(c == new_line) {
            ++row;
            col = 0;
        }
    }
}

void initialize() {
    for(int i = 0; i < ROW; ++i) {
        for(int j = 0; j < COL; ++j) {
            visited[i][j] = NOT_VISITED;
            grid[i][j] = space;
        }
    }
}

void flood_fill(int y, int x, int c) {
    if(y >= 0 && y < ROW && x >= 0 && x < COL && grid[y][x] == space) {
        grid[y][x] = c;
        flood_fill(y, x + 1, c);
        flood_fill(y, x - 1, c);
        flood_fill(y + 1, x, c);
        flood_fill(y - 1, x, c);
    }
}

bool isCross(int y, int x) {
    return (y >= 0 && y < ROW && x >= 0 && x < COL && grid[y][x] == cross);
}

bool isUnderLine(int y, int x) {
    return (y >= 0 && y < ROW && x >= 0 && x < COL && grid[y][x] == under_line);
}

void flood_fill2(int y, int x, int c) {
    if(y >= 0 && y < ROW && x >= 0 && x < COL && grid[y][x] == sharp && visited[y][x] == NOT_VISITED) {
        visited[y][x] = VISITED;
        if(!(isCross(y + 1, x) || isCross(y - 1, x) || isCross(y, x + 1) || isCross(y, x - 1))) {
            if(!isUnderLine(y, x)) {
                grid[y][x] = space;
            }
        }
        flood_fill2(y, x + 1, c);
        flood_fill2(y, x - 1, c);
        flood_fill2(y + 1, x, c);
        flood_fill2(y - 1, x, c);
    }
}

void behind_process() {
    for(int i = 0; i < ROW; ++i) {
        for(int j = COL - 1; j >= 0; --j) {
            if(grid[i][j] == space) {
                grid[i][j] = new_line;
            } else {
                break;
            }
        }
    }
}

void draw() {
    int star_row, star_col;
    for(int i = 0; i < ROW; ++i) {
        for(int j = 0; j < COL; ++j) {
            if(grid[i][j] == star) {
                star_row = i;
                star_col = j;
                grid[star_row][star_col] = space;
                goto SEARCH_END;
            }
        }
    }
SEARCH_END:
    flood_fill(star_row, star_col, sharp);
    flood_fill2(star_row, star_col, space);
    behind_process();
}

void output() {
    draw();
    bool bLoop = true;
    for(int i = 0; bLoop && i < ROW; ++i) {
        for(int j = 0; j < COL && grid[i][j] != new_line; ++j) {
            putchar((char)grid[i][j]);
            if(grid[i][j] == under_line) {
                bLoop = false;
            }
        }
        puts("");
    }
}

int main() {
    scanf("%d", &cases);
    get_newline();
    while(cases--) {
        initialize();
        input();
        output();
    }
    return 0;
}
